<!DOCTYPE HTML>
<html lang="zh-CN">


<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta name="keywords" content="【实践】基于LiteOS的智慧农业案例实验分享, ZhengN_Blog">
    <meta name="description" content="最近在指导一位读者朋友做毕业设计，该毕设是关于端云互通的，基于小熊派+LiteOS+华为云。
在指导他的过程中我也学到了不少东西，这里通过一个案例实验（智慧农业）给大家分享一些知识。

实验框图
相关模块简介1、STM32L431RCT6
">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>【实践】基于LiteOS的智慧农业案例实验分享 | ZhengN_Blog</title>
    <link rel="icon" type="image/jpeg" href="/favicon.jpg">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">
    <style type="text/css">
        
    </style>

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>

<header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">ZhengN_Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>首页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/archives" class="waves-effect waves-light">
            
            <i class="fa fa-archive"></i>
            
            <span>归档</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>关于</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <i class="fa fa-address-book"></i>
            
            <span>友情链接</span>
        </a>
    </li>
    
    <li>
        <a href="#searchModal" class="modal-trigger waves-effect waves-light">
            <i id="searchIcon" class="fa fa-search" title="搜索"></i>
        </a>
    </li>
</ul>

<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">ZhengN_Blog</div>
        <div class="logo-desc">
            
            printf(&#34;每天进步一点点~&#34;);
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                首页
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/archives" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-archive"></i>
                
                归档
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                关于
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-address-book"></i>
                
                友情链接
            </a>
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/zhengnianli/stm32_weather" class="waves-effect waves-light" target="_blank">
                <i class="fa fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>

        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/zhengnianli/stm32_weather" class="github-corner tooltipped hide-on-med-and-down" target="_blank" data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewbox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/>
    </svg>
</a>
        
    </nav>

</header>





<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/5.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        【实践】基于LiteOS的智慧农业案例实验分享
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 20px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/STM32/" target="_blank">
                                <span class="chip bg-color">STM32</span>
                            </a>
                        
                            <a href="/tags/LiteOS/" target="_blank">
                                <span class="chip bg-color">LiteOS</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fa fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/STM32笔记/" class="post-category" target="_blank">
                                STM32笔记
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                <div class="post-date info-break-policy">
                    <i class="fa fa-calendar-minus-o fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2020-04-05
                </div>

                
                    
                    <div class="info-break-policy">
                        <i class="fa fa-file-word-o fa-fw"></i>文章字数:&nbsp;&nbsp;
                        2.9k
                    </div>
                    

                    
                    <div class="info-break-policy">
                        <i class="fa fa-clock-o fa-fw"></i>阅读时长:&nbsp;&nbsp;
                        10 分
                    </div>
                    
                
				
				
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="fa fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">
        <div class="card-content article-card-content">
            <div id="articleContent">
                <p>最近在指导一位读者朋友做毕业设计，该毕设是关于端云互通的，基于小熊派+LiteOS+华为云。</p>
<p>在指导他的过程中我也学到了不少东西，这里通过一个案例实验（智慧农业）给大家分享一些知识。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUBY4.png" alt></p>
<h2 id="实验框图"><a href="#实验框图" class="headerlink" title="实验框图"></a>实验框图</h2><p><img src="https://s1.ax1x.com/2020/06/02/ttUdTU.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttU0kF.png" alt></p>
<h2 id="相关模块简介"><a href="#相关模块简介" class="headerlink" title="相关模块简介"></a>相关模块简介</h2><h3 id="1、STM32L431RCT6"><a href="#1、STM32L431RCT6" class="headerlink" title="1、STM32L431RCT6"></a>1、STM32L431RCT6</h3><p><img src="https://s1.ax1x.com/2020/06/02/ttUylR.jpg" alt></p>
<h3 id="2、LiteOS"><a href="#2、LiteOS" class="headerlink" title="2、LiteOS"></a>2、LiteOS</h3><p><code>LiteOS</code>是华为开发的轻量级实时操作系统：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUUmV.png" alt></p>
<p><code>LiteOS</code>源码<code>GitHub</code>仓库链接：</p>
<blockquote>
<p><a href="https://github.com/LiteOS/LiteOS" target="_blank" rel="noopener">https://github.com/LiteOS/LiteOS</a></p>
</blockquote>
<p>其源码一级目录结构如下：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUawT.png" alt></p>
<p>其内核包括任务管理、内存管理、时间管理、通信机制、中断管理、队列管理、事件管理、定时器等操作系统基础组件，可以单独运行。</p>
<p>Huawei LiteOS是一个支持多任务的操作系统。在Huawei LiteOS中，一个任务表示一个线程。  其任务是抢占式调度机制，同时支持时间片轮转调度方式。  </p>
<p>高优先级的任务可打断低优先级任务，低优先级任务必须在高优先级任务阻塞或结束后才能得到调度。  </p>
<p>创建任务示例：</p>
<pre class=" language-c"><code class="language-c">UINT32 <span class="token function">creat_test_task</span><span class="token punctuation">(</span>VOID<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  UINT32 uwRet <span class="token operator">=</span> LOS_OK<span class="token punctuation">;</span>
  TSK_INIT_PARAM_S task_init_param<span class="token punctuation">;</span>
  UINT32 TskHandle<span class="token punctuation">;</span>

  task_init_param<span class="token punctuation">.</span>usTaskPrio <span class="token operator">=</span> TASK_PRIO<span class="token punctuation">;</span>    <span class="token comment" spellcheck="true">/* 任务优先级 */</span>
  task_init_param<span class="token punctuation">.</span>pcName <span class="token operator">=</span> <span class="token string">"test_task"</span><span class="token punctuation">;</span>    <span class="token comment" spellcheck="true">/* 任务名称 */</span>
  task_init_param<span class="token punctuation">.</span>pfnTaskEntry <span class="token operator">=</span> <span class="token punctuation">(</span>TSK_ENTRY_FUNC<span class="token punctuation">)</span>test_task<span class="token punctuation">;</span> <span class="token comment" spellcheck="true">/* 任务入口函数 */</span>
  task_init_param<span class="token punctuation">.</span>uwStackSize <span class="token operator">=</span> STACK_SIZE<span class="token punctuation">;</span> <span class="token comment" spellcheck="true">/* 任务栈大小 */</span>

  <span class="token comment" spellcheck="true">/* 任务创建 */</span>
  uwRet <span class="token operator">=</span> <span class="token function">LOS_TaskCreate</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>TskHandle<span class="token punctuation">,</span> <span class="token operator">&amp;</span>task_init_param<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">if</span><span class="token punctuation">(</span>LOS_OK <span class="token operator">!=</span> uwRet<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
      <span class="token keyword">return</span> uwRet<span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token keyword">return</span> uwRet<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<h3 id="3、华为云平台"><a href="#3、华为云平台" class="headerlink" title="3、华为云平台"></a>3、华为云平台</h3><p>本次实验的云平台为华为的<code>OceanConnect</code>物联网平台：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaFBV.png" alt></p>
<p>其云端开发框图如下：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUWTO.png" alt></p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUcOx.png" alt></p>
<p>我们主要是用来做实验，着重关注<code>红框里的内容</code>。</p>
<p>下面简单介绍一下<code>Profile文件</code>、<code>编解码器插件</code>这两块大家可能比较陌生的部分：</p>
<p><strong>（1）Profile文件开发</strong></p>
<p><code>Profile</code>（即产品模型）是用来描述一款产品中的设备“是什么”、“能做什么”以及“如何控制该设备”的文件。</p>
<p>在物联网平台集成对接中需要先创建Profile，因为Profile里面定义了设备上报的数据和应用服务器下发的命令包含了哪些字段。</p>
<p>定义Profile，即在物联网平台构建一款设备的<code>抽象模型</code>，使平台理解该款设备支持的服务、属性、命令、升级能力等信息。</p>
<p>Profile主要包含产品信息、服务能力和维护能力三部分：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUDfJ.png" alt></p>
<p>本次实验我们主要关注<code>红框部分</code>，其具体表现如：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUsp9.png" alt></p>
<p><strong>（2）编解码插件开发</strong></p>
<p>一款产品的设备上报数据时，如果“数据格式”为<code>二进制码流</code>，则该产品需要进行编解码插件开发；如果“数据格式”为<code>JSON</code>，则该产品下不需要进行编解码插件开发。两种数据举例</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttU661.png" alt></p>
<p>作为物联网的终端设备，比较讲究的就是<code>功耗</code>问题了，这个问题也关乎到通信传输的数据量的问题。</p>
<p>上图举例的两种数据格式其实代表着同样的信息，虽然对于我们程序员而言，我们更容易读懂<code>JSON</code>格式的数据包含的信息；但是对于设备而言，其更喜欢二进制流格式的数据了。</p>
<p>因为使用二进制流来表示的话传输的数据量就会小很多，进而可以<code>降低功耗</code>。其实这个二进制流格式也很好理解，是按照特定格式的，比如：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttU2m6.png" alt></p>
<p>本次实验我们设备端发送与接收的数据均为二进制流格式数据，因此需要进行云端编码器插件的开发。下面是设备数据上报的流程：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUR0K.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttUhkD.png" alt></p>
<h3 id="4、BH1750光强度传感器"><a href="#4、BH1750光强度传感器" class="headerlink" title="4、BH1750光强度传感器"></a>4、BH1750光强度传感器</h3><p><code>BH1750</code>是一种用于两线制串行总线接口的<code>16位</code>数字型光强度传感器集成电路。利用它的高分辨率可以探测较大范围的光强度变化。（<code>1lx~65535lx</code>）。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUopd.png" alt></p>
<p><strong>主要特性：</strong></p>
<ul>
<li>支持 IIC BUS 接口</li>
<li>光源依赖性弱</li>
<li>有两种可选的 IIC slave 地址</li>
<li>最小误差变动在±20% </li>
</ul>
<h3 id="5、SHT30温湿度模块"><a href="#5、SHT30温湿度模块" class="headerlink" title="5、SHT30温湿度模块"></a>5、SHT30温湿度模块</h3><p>温湿度传感器 <code>SHT30</code>的温度范围为<code>-40℃~125℃</code> ，湿度范围为<code>0%RH~100%RH</code>。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUT1A.png" alt></p>
<p><strong>主要特性：</strong>    </p>
<ul>
<li>完全校准的线性化，温度补偿式的数字输出 </li>
<li>电压范围 2.4V-5.5V</li>
<li>通信速度高达 1MHz 的 IIC 接口，两个可选的用户地址</li>
<li>相对湿度误差± 2%RH</li>
<li>温度误差± 0.3%</li>
</ul>
<h3 id="6、补光灯模块"><a href="#6、补光灯模块" class="headerlink" title="6、补光灯模块"></a>6、补光灯模块</h3><p>与普通的LED的控制一样，通过一个GPIO来控制其亮、灭。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttU4te.png" alt></p>
<h3 id="7、直流电机模块"><a href="#7、直流电机模块" class="headerlink" title="7、直流电机模块"></a>7、直流电机模块</h3><p>通过一个GPIO来控制其转、停。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttU76I.png" alt></p>
<h2 id="重要步骤解析"><a href="#重要步骤解析" class="headerlink" title="重要步骤解析"></a>重要步骤解析</h2><p>我们可以用<code>Keil MDK</code>来编写、编译代码，也可以使用<code>LiteOS Studio</code>来编写、编译代码。</p>
<p>在解析重要步骤之前有必要介绍一下<code>LiteOS Studio</code>。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttap1s.png" alt></p>
<p><code>LiteOS Studio</code>是LiteOS集成开发环境，一站式开发工具，支持C、C++、汇编等语言，让您快速，高效的进行物联网开发。</p>
<p>主题默认是大家都喜欢的暗黑色，使用起来也比较简单，其用Makefile来管理工程，使用时添加新的源文件需要同步更新<code>Makefile</code>文件：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaN3d.png" alt></p>
<h3 id="1、读取传感器数据并显示至LCD"><a href="#1、读取传感器数据并显示至LCD" class="headerlink" title="1、读取传感器数据并显示至LCD"></a>1、读取传感器数据并显示至LCD</h3><p>准备<code>BH1750</code>与<code>SHT30</code>传感器驱动。这里跟初学者分享一点经验，看这些传感器驱动代码的时候不要只看代码。</p>
<p>这种与实际硬件（芯片）密切相关的代码光看代码是没有多大意义的，只会越看越懵。</p>
<p>因此正确姿势应该是对照着<code>datasheet</code>一起看，需要写出这些代码得好好研读<code>datasheet</code>。</p>
<p>一般比较成熟的传感器驱动网上都有很多现成的可以直接用的，多数情况下我们很少去亲自写这个。</p>
<p>特别是工作之后，能copy的代码坚决不自己写，哈哈，老板可不看你代码写得多秀，只看你任务完成得怎么样。</p>
<p>但是还是有必要了解一下这些驱动代码怎么写出来的方法，万一某天真的需要我们自己写呢。下面我们从例程代码中扣出一些核心代码：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUjAS.png" alt></p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUqnP.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttUO78.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttUL0f.png" alt></p>
<p>我们最终要用到的就是最后一个函数来读取传感器数据，然后显示在LCD上，核心代码：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUvtg.png" alt></p>
<p>结果：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttafuq.jpg" alt></p>
<p>这个结果多了一个烟感数据。这里简单说明一下：写这篇笔记时用的是智慧农业的模块。后来才加了一个烟感模块，改起来比较麻烦就没去改了，所以上面的一些图的说明没有烟感模块。</p>
<h3 id="2、云端配置"><a href="#2、云端配置" class="headerlink" title="2、云端配置"></a>2、云端配置</h3><p>在设备端接入云端之前，遇到对云端进行相应的配置。这里也是抽取出重要的步骤，具体的步骤可以查看华为云上相关的文档，很详细：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttUxhQ.png" alt></p>
<p>文档链接：</p>
<blockquote>
<p><a href="https://support.huaweicloud.com/devg-IoT/iot_02_9994.html" target="_blank" rel="noopener">https://support.huaweicloud.com/devg-IoT/iot_02_9994.html</a></p>
</blockquote>
<p><strong>（1）创建产品：</strong></p>
<p><img src="https://s1.ax1x.com/2020/06/02/tta9cn.png" alt></p>
<p>有几种方式创建产品，这里我们选择自定义的方式，学会了自定义的方式创建产品了，其它几种方式就更简单了。</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaSpj.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttaoUU.png" alt></p>
<p><strong>（2）Profile、编解码器插件开发</strong></p>
<p>接着进行产品开发，主要是进行Profile文件与编解码器插件的开发。</p>
<p>Profile文件有两种开发方式：离线的方式与在线的方式。我们使用在线的方式创建，创建的Profile文件如下：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaEAU.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttain0.png" alt></p>
<p>编解码器插件的开发依赖与Profile文件，我们创建的编解码器插件如下：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaVNF.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttaZh4.png" alt></p>
<p><strong>（3）调测</strong></p>
<p>接着验证我们的Profile文件与编解码器插件，这里有两种方法验证.</p>
<p>一是创建<code>真实的设备</code>，这个需要我们真实的设备端进行连接测试，下面我们再做这一步；</p>
<p>二是使用<code>虚拟的设备</code>。这里我们使用虚拟的设备进行验证：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaJ4e.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttalB6.png" alt></p>
<h3 id="3、设备端开发"><a href="#3、设备端开发" class="headerlink" title="3、设备端开发"></a>3、设备端开发</h3><p>设备端我们使用LiteOS SDK端云互通组件<code>agent tiny</code>对接IoT平台。</p>
<p>借助这个组件我们只需要调用几个API函数就可以很方便地连接华为IOT平台，其重要接口函数如下：</p>
<pre class=" language-c"><code class="language-c"><span class="token comment" spellcheck="true">/* LiteOS SDK端云互通组件的初始化接口 */</span>
<span class="token keyword">int</span> <span class="token function">atiny_init</span><span class="token punctuation">(</span>atiny_param_t<span class="token operator">*</span> atiny_params<span class="token punctuation">,</span> <span class="token keyword">void</span><span class="token operator">*</span><span class="token operator">*</span> phandle<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/* LiteOS SDK端云互通组件的主函数体 */</span>
<span class="token keyword">int</span> <span class="token function">atiny_bind</span><span class="token punctuation">(</span>atiny_device_info_t<span class="token operator">*</span> device_info<span class="token punctuation">,</span> <span class="token keyword">void</span><span class="token operator">*</span> phandle<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/* LwM2M标准对象向设备下发命令的统一入口 */</span>
<span class="token keyword">int</span> <span class="token function">atiny_cmd_ioctl</span><span class="token punctuation">(</span>atiny_cmd_e cmd<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> arg<span class="token punctuation">,</span> <span class="token keyword">int</span> len<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">/* LiteOS SDK端云互通组件数据上报接口 */</span>
<span class="token keyword">int</span> <span class="token function">atiny_data_report</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token operator">*</span> phandle<span class="token punctuation">,</span> data_report_t<span class="token operator">*</span> report_data<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
<p>设备对接IOT平台的流程示意图：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/tta8AO.png" alt></p>
<p>其实本云端互通实验主要围绕的就是一个<code>agent_tiny</code>任务，其任务入口函数就是这个流程图上的<code>agent_tiny_entry</code>函数。</p>
<p>这个入口函数里面主要做的内容是：atiny的初始化、对于入参atiny_params的设定（要根据具体的业务来进行）。</p>
<p>还有创建一些子任务（数据采集任务、数据上报任务、下发命令的应答任务），最后进行到。</p>
<p>核心代码如端云互通组件的主函数体，具体核心代码如：</p>
<pre class=" language-c"><code class="language-c"><span class="token keyword">void</span> <span class="token function">agent_tiny_entry</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span>
<span class="token punctuation">{</span>
  UINT32 uwRet <span class="token operator">=</span> LOS_OK<span class="token punctuation">;</span>
  atiny_param_t <span class="token operator">*</span>atiny_params<span class="token punctuation">;</span>
  atiny_security_param_t  <span class="token operator">*</span>iot_security_param <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span>
  atiny_security_param_t  <span class="token operator">*</span>bs_security_param <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span>

  atiny_device_info_t <span class="token operator">*</span>device_info <span class="token operator">=</span> <span class="token operator">&amp;</span>g_device_info<span class="token punctuation">;</span>

  <span class="token comment" spellcheck="true">//  省略部分内容。。。。。。。。。。。。</span>
  device_info<span class="token operator">-></span>endpoint_name <span class="token operator">=</span> g_endpoint_name<span class="token punctuation">;</span>
  atiny_params <span class="token operator">=</span> <span class="token operator">&amp;</span>g_atiny_params<span class="token punctuation">;</span>
  atiny_params<span class="token operator">-></span>server_params<span class="token punctuation">.</span>binding <span class="token operator">=</span> <span class="token string">"UQ"</span><span class="token punctuation">;</span>
  <span class="token comment" spellcheck="true">//  省略部分内容。。。。。。。。。。。。</span>

  <span class="token comment" spellcheck="true">/* LiteOS SDK端云互通组件的初始化接口 */</span>
  <span class="token keyword">if</span><span class="token punctuation">(</span>ATINY_OK <span class="token operator">!=</span> <span class="token function">atiny_init</span><span class="token punctuation">(</span>atiny_params<span class="token punctuation">,</span> <span class="token operator">&amp;</span>g_phandle<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
      <span class="token keyword">return</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment" spellcheck="true">/* 创建数据采集任务 */</span>
  uwRet <span class="token operator">=</span> <span class="token function">creat_collection_task</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>uwRet <span class="token operator">!=</span> LOS_OK<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment" spellcheck="true">/* 创建数据上报任务 */</span>
  uwRet <span class="token operator">=</span> <span class="token function">creat_report_task</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">if</span><span class="token punctuation">(</span>LOS_OK <span class="token operator">!=</span> uwRet<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
      <span class="token keyword">return</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment" spellcheck="true">/* 创建一个信号量 */</span>
  uwRet <span class="token operator">=</span> <span class="token function">LOS_SemCreate</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token operator">&amp;</span>reply_sem<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>uwRet <span class="token operator">!=</span> LOS_OK<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment" spellcheck="true">/* 创建下发命令的应答任务 */</span>
  uwRet <span class="token operator">=</span> <span class="token function">creat_reply_report_task</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">if</span> <span class="token punctuation">(</span>uwRet <span class="token operator">!=</span> LOS_OK<span class="token punctuation">)</span>
  <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment" spellcheck="true">/* LiteOS SDK端云互通组件的主函数体 */</span>
  <span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span><span class="token function">atiny_bind</span><span class="token punctuation">(</span>device_info<span class="token punctuation">,</span> g_phandle<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span></code></pre>
<p>更具体的代码就不展开了，篇幅好像有点长了。。。</p>
<p>除此之外，在对接云端之前，还需要一个可以联网的媒介，这里我们选用的是ESP8266，使用AT设备框架来管理我们的ESP8266设备：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/tta1HK.png" alt></p>
<p>现在，我们就可以使用真实的设备对接云端了，对接云端需要一个设备标识码，用<code>ESP8266</code>模块时需要我们自己创建一个标识码。</p>
<p>用其它联网模块如<code>NB-IOT</code>模块则只需使用模块出厂自带的设备码即可。这里我们创建的设备标识码为：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttaGND.png" alt></p>
<p>这个标识码其实就是在我们上面的<code>agent_tiny_entry</code>函数中有配置给<code>device_info</code>设备结构体了。然后使用这个标识码在云端创建设备：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttahD0.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttat9H.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttaUgA.png" alt><br><img src="https://s1.ax1x.com/2020/06/02/ttay4g.png" alt></p>
<h3 id="4、web应用开发"><a href="#4、web应用开发" class="headerlink" title="4、web应用开发"></a>4、web应用开发</h3><p>上面在调试阶段已经可以上传云端到IOT平台了，也可以看到数据了。但是那些数据对于用户来说总归是看不习惯吧，我们开发产品就是为了给用户使用、给用户看的。</p>
<p>所以最终体现出来给用户的不应该是一堆数据，而是一个对用户较友好的可视化界面。</p>
<p>华为物联网开发平台也给我们提供了web应用开发的环境：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttasUS.png" alt></p>
<p>这里的应用开发也比较简单，通过拖拽一些空间，简单修改一下控件的一些属性即可：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttacCQ.png" alt></p>
<p>最终效果：</p>
<p><img src="https://s1.ax1x.com/2020/06/02/ttag3j.png" alt></p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>以上就是本次分享的智慧农业案例实验，本次实验用了华为IOT平台，其实其它平台用起来也是类似的，之后有时间再分享其它云平台的案例实验。</p>
<p>上面分享的很多步骤其实不算详细，关于这个实验更详细的步骤内容可以联系我获取相关文档资料、包括代码。</p>
<p>原创不易，感谢阅读，期待在看、分享~</p>
<hr>
<p>我的个人博客：<a href="https://www.lizhengnian.cn/">https://www.lizhengnian.cn/</a></p>
<p>我的微信公众号：嵌入式大杂烩</p>
<p>我的CSDN博客：<a href="https://blog.csdn.net/zhengnianli" target="_blank" rel="noopener">https://blog.csdn.net/zhengnianli</a></p>
<p><img src="https://s1.ax1x.com/2020/06/22/NGV7Oe.png" alt></p>

            </div>
            <hr>

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">欢迎关注ZhengN的微信公众号</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <!--<ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微信公众号</a></li>
                    </ul>-->
					<!--
                    <div id="alipay">
                        <img src="" class="reward-img" alt="支付宝打赏二维码">
                    </div>
					-->
                    <div id="wechat">
                        <img src="/medias/reward/wechat.jpg" class="reward-img" alt="微信公众号二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>
            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            


        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments input[type=text],
    #vcomments input[type=email],
    #vcomments input[type=url],
    #vcomments textarea {
        box-sizing: border-box;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #42b983;
        font-weight: 500;
        text-decoration: underline;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div id="vcomments" class="card-content"></div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'Vc276uuqkd8y8heuqzShe9p1-gzGzoHsz',
        appKey: 'bUwy6lANpgeVdpcQamMtC8QD',
        notify: 'false' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: '快来快活呀！^_^'
    });
</script>
    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6 overflow-policy" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fa fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2020/04/05/wifi-mo-kuai-at-zhi-ling-ce-shi-wifi-tong-xin-mo-zu-bing-huo-qu-tian-qi-shu-ju/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/19.jpg" class="responsive-img" alt="AT指令测试WIFI通信模组并获取天气数据">
                        
                        <span class="card-title">AT指令测试WIFI通信模组并获取天气数据</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            ESP8266是一个很好玩的模块，应该有很多朋友都有玩过了，但也不乏有很多没玩过的朋友，下面进行简单介绍。本次笔记分享的是ESP8266 WiFi通信模组的AT指令测试实验。
ESP8266的认识
首先简单认识一下ESP8266。ESP82
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2020-04-05
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/嵌入式/" class="post-category" target="_blank">
                                    嵌入式
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/STM32/" target="_blank">
                        <span class="chip bg-color">STM32</span>
                    </a>
                    
                    <a href="/tags/ESP8266/" target="_blank">
                        <span class="chip bg-color">ESP8266</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6 overflow-policy" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fa fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2020/03/14/c-yu-yan-zhi-zhen-zhi-shi-da-hui-zong/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/10.jpg" class="responsive-img" alt="【C语言】指针知识大汇总">
                        
                        <span class="card-title">【C语言】指针知识大汇总</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            指针在C语言中是一块很重要的内容，也是比较难理解的一块内容，我们需要反复理解反复巩固才可以对其有所了解。之前也分享过指针相关的笔记，但是都比较杂，本篇笔记汇总一下指针相关的内容，包含了挺多指针相关的基础知识点。这篇笔记有点长，可以收藏下来慢
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2020-03-14
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/C语言/" class="post-category" target="_blank">
                                    C语言
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/C语言/" target="_blank">
                        <span class="chip bg-color">C语言</span>
                    </a>
                    
                    <a href="/tags/嵌入式/" target="_blank">
                        <span class="chip bg-color">嵌入式</span>
                    </a>
                    
                    <a href="/tags/位操作/" target="_blank">
                        <span class="chip bg-color">位操作</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>



    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title"><i class="fa fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fa fa-list"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            // headingsOffset: -205,
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).slideUp(500);
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).slideDown(500);
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>
    

</main>


<footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            本站由&copy;<a href="https://zhengnianli.github.io/" target="_blank">ZhengNian</a>基于
            <a href="https://hexo.io/" target="_blank">Hexo</a> 的
            <a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">hexo-theme-matery</a>主题搭建.

            
                &nbsp;<i class="fa fa-area-chart"></i>&nbsp;站点总字数:&nbsp;
                <span class="white-color">187.2k</span>
            

            
			
                <br>
                
                <span id="busuanzi_container_site_pv">
                    <i class="fa fa-heart-o"></i>
                    本站总访问量 <span id="busuanzi_value_site_pv" class="white-color"></span>
                </span>
                
                
                <span id="busuanzi_container_site_uv">
                    <i class="fa fa-users"></i>
                    次,&nbsp;访客数 <span id="busuanzi_value_site_uv" class="white-color"></span> 人.
                </span>
                
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/zhengnianli" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fa fa-github"></i>
    </a>



    <a href="mailto:2238184039@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fa fa-envelope-open"></i>
    </a>



    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=2238184039" class="tooltipped" data-tooltip="QQ联系我: 2238184039" data-position="top" data-delay="50">
        <i class="fa fa-qq"></i>
    </a>



    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fa fa-rss"></i>
    </a>
</div>
    </div>
</footer>

<div class="progress-bar"></div>


<!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fa fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字" class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
$(function () {
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
});
</script>
<!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


<script src="/libs/materialize/materialize.min.js"></script>
<script src="/libs/masonry/masonry.pkgd.min.js"></script>
<script src="/libs/aos/aos.js"></script>
<script src="/libs/scrollprogress/scrollProgress.min.js"></script>
<script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
<script src="/js/matery.js"></script>

<!-- Global site tag (gtag.js) - Google Analytics -->



    <script src="/libs/others/clicklove.js"></script>


    <script async src="/libs/others/busuanzi.pure.mini.js"></script>


</body>
</html>